package com.yunjian.admin.controller;

import com.github.pagehelper.PageInfo;
import com.yunjian.admin.util.PwdUtil;
import com.yunjian.admin.vo.WebResult;
import com.yunjian.core.basic.model.SUser;
import com.yunjian.core.basic.model.SUserExample;
import com.yunjian.core.basic.model.SUserRoleExample;
import com.yunjian.core.basic.model.SUserRoleKey;
import com.yunjian.core.basic.service.SRoleService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yunjian.core.basic.service.SUserRoleService;
import com.yunjian.core.basic.service.SUserService;
import com.yunjian.core.basic.service.SequenceService;
import com.yunjian.core.basic.service.UserLogService;
import com.yunjian.core.busi.enums.Education;
import com.yunjian.core.busi.enums.EmployeeStatus;
import com.yunjian.core.busi.enums.MaritalStatus;
import com.yunjian.core.busi.enums.Post;
import com.yunjian.core.busi.enums.Sex;
import com.yunjian.core.busi.model.Employee;
import com.yunjian.core.busi.model.EmployeeExample;
import com.yunjian.core.busi.service.EmployeeService;
import com.yunjian.core.busi.service.EmployeeVoService;
import com.yunjian.core.busi.service.StoreService;
import com.yunjian.core.busi.vo.EmployeeVo;
import com.yunjian.util.StringUtil;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author tsh721@126.com
 */
@Controller
@RequestMapping("/employee")
public class EmployeeController {

    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    private static final Logger logger = LoggerFactory.getLogger(EmployeeController.class);

    @Autowired
    private EmployeeVoService employeeVoService;
    @Autowired
    private UserLogService userLogService;
    @Autowired
    private SequenceService sequenceService;
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private SUserRoleService userRoleService;
    @Autowired
    private SUserService userService;
    @Autowired
    private SRoleService roleService;
    @Autowired
    private StoreService storeService;

    /**
     *
     * @param page 页号
     * @param rows 列数
     * @param userId 员工ID
     * @param name 员工姓名
     * @param tel 联系电话
     * @param entryTime 入职时间
     * @param roleId 所属角色ID
     * @param post 职位：职业顾问, 门店经理, 片区经理, 租售经理, 总监, 系统管理员
     * @param storeId 门店ID，支持多个ID,用英文逗号隔开
     * @param status 员工状态：在职, 离职;
     * @return 返回参数：
     */
    @ResponseBody
    @RequestMapping("/list")
    @ApiOperation(value = "员工列表")
    @RequiresPermissions("employee:list")
    public WebResult<PageInfo<EmployeeVo>> list(
            @ApiParam(value = "页面Size") @RequestParam(required = true) int rows,
            @ApiParam(value = "页") @RequestParam(required = true) int page,
            @ApiParam(value = "过滤条件-员工ID") String userId,
            @ApiParam(value = "过滤条件-员工姓名") String name,
            @ApiParam(value = "过滤条件-联系电话") String tel,
            @ApiParam(value = "过滤条件-入职时间") String entryTime,
            @ApiParam(value = "过滤条件-角色ID") String roleId,
            @ApiParam(value = "过滤条件-当前职位") Post post,
            @ApiParam(value = "过滤条件-门店ID") String storeId,
            @ApiParam(value = "过滤条件-员工状态") EmployeeStatus status) {
        SUser suser = (SUser) SecurityUtils.getSubject().getPrincipal();
        logger.info("用户[{}]查看员工列表", suser.getUserId());
        userLogService.info(suser.getUserId(), SecurityUtils.getSubject().getSession().getHost(), "查看员工列表");
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        List<String> userIds = new ArrayList<>();
        if (StringUtils.isNotBlank(roleId)) {
            SUserRoleExample urExample = new SUserRoleExample();
            SUserRoleExample.Criteria urCriteria = urExample.createCriteria();
            urCriteria.andRoleIdEqualTo(roleId);
            if (!userIds.isEmpty()) {
                urCriteria.andUserIdIn(userIds);
            }
            List<SUserRoleKey> userRoleList = userRoleService.selectByExample(urExample);
            userIds.clear();
            userRoleList.stream().forEach((userRole) -> {
                userIds.add(userRole.getUserId());
            });
            if (userIds.isEmpty()) {
                return emptyResult(page, rows);
            }
            criteria.andUserIdIn(userIds);
        }
        if (StringUtils.isNotBlank(tel)) {
            SUserExample userExample = new SUserExample();
            SUserExample.Criteria userCriteria = userExample.createCriteria();
            userCriteria.andUserTelEqualTo(tel);
            if (!userIds.isEmpty()) {
                userCriteria.andUserIdIn(userIds);
            }
            List<SUser> userList = userService.selectByExample(userExample);
            userIds.clear();
            userList.stream().forEach((user) -> {
                userIds.add(user.getUserId());
            });
            if (userIds.isEmpty()) {
                return emptyResult(page, rows);
            }
            criteria.andUserIdIn(userIds);
        }

        criteria.andDelFlagEqualTo(0);
        if (StringUtils.isNotBlank(name)) {
            criteria.andNameLike("%" + name + "%");
        }
        if (StringUtil.isNotEmpty(userId)) {
            criteria.andUserIdLike("%" + userId + "%");
        }
        if (StringUtils.isNotBlank(entryTime)) {
            try {
                Date entryDate = df.parse(entryTime);
                criteria.andEntryTimeEqualTo(entryDate);
            } catch (ParseException ex) {
                logger.error("参数错误，entryTime：" + entryTime + "不是可解析的日期格式");
            }
        }
        if (null != post) {
            criteria.andPostEqualTo(post.name());
        }
        if (StringUtils.isNotBlank(storeId)) {
            String[] arr = storeId.split(",");
            criteria.andStoreIdIn(Arrays.asList(arr));
        }
        if (null != status) {
            criteria.andStatusEqualTo(status.name());
        }
        WebResult<PageInfo<EmployeeVo>> ret = new WebResult<>();
        ret.setAttach(employeeVoService.selectPagedByExample(page, rows, example));
        return ret.setCoder(WebResult.Coder.SUCCESS);
    }

    private WebResult<PageInfo<EmployeeVo>> emptyResult(int page, int rows) {
        WebResult<PageInfo<EmployeeVo>> ret = new WebResult<>();
        ret.setAttach(employeeVoService.emptyPaged(page, rows));
        return ret.setCoder(WebResult.Coder.SUCCESS);
    }

    @ResponseBody
    @RequestMapping("/register")
    @ApiOperation(value = "录入新员工")
    @RequiresPermissions("employee:add")
    public WebResult<String> register(
            @ApiParam(value = "登录帐号") String account,
            @ApiParam(value = "登录密码") @RequestParam(required = true) String password,
            @ApiParam(value = "员工姓名") String name,
            @ApiParam(value = "身份证号") String idcard,
            @ApiParam(value = "员工性别") Sex sex,
            @ApiParam(value = "联系电话") String tel,
            @ApiParam(value = "联系地址") String address,
            @ApiParam(value = "籍贯") String nativePlace,
            @ApiParam(value = "出生日期") String birth,
            @ApiParam(value = "邮箱地址") String email,
            @ApiParam(value = "学历") Education education,
            @ApiParam(value = "入职时间") String entryTime,
            @ApiParam(value = "婚姻状态") MaritalStatus maritalstatus,
            @ApiParam(value = "当前职位") Post post,
            @ApiParam(value = "门店ID") String storeId,
            @ApiParam(value = "角色ID") String roleId) {
        WebResult<String> ret = new WebResult<>();
        SUser sessionUser = (SUser) SecurityUtils.getSubject().getPrincipal();
        logger.info("用户[{}]-添加新员工", sessionUser.getUserId());
        SUserExample mUserEp;
        List<SUser> sUsers;
        if (StringUtils.isNotBlank(account)) {
            mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserAccountEqualTo(account);
            sUsers = userService.selectByExample(mUserEp);
            if (sUsers != null && !sUsers.isEmpty()) {
                return new WebResult<String>().setCoder(WebResult.Coder.C1211);
            }
        }
        if (StringUtils.isNotBlank(email)) {
            mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserMailEqualTo(email);
            sUsers = userService.selectByExample(mUserEp);
            if (sUsers != null && !sUsers.isEmpty()) {
                return new WebResult<String>().setCoder(WebResult.Coder.C1212);
            }
        }
        if (StringUtils.isNotBlank(tel)) {
            mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserTelEqualTo(tel);
            sUsers = userService.selectByExample(mUserEp);
            if (sUsers != null && !sUsers.isEmpty()) {
                return new WebResult<String>().setCoder(WebResult.Coder.C1213);
            }
        }

        String userId = sequenceService.genUserId();
        logger.debug("开始创建用户, userId =" + userId);
        SUser user = new SUser();
        user.setUserId(userId);
        StringBuilder sb = new StringBuilder("User : userId-").append(userId);
        if (StringUtils.isNotBlank(account)) {
            user.setUserAccount(account);
            sb.append("\n").append("account-").append(account);
        }
        user.setUserPwd(PwdUtil.getPwd(password));
        sb.append("\n").append("password-").append(password);
        if (StringUtils.isNotBlank(tel)) {
            user.setUserTel(tel);
            sb.append("\n").append("tel-").append(tel);
        }
        if (StringUtils.isNotBlank(email)) {
            user.setUserMail(email);
            sb.append("\n").append("email-").append(email);
        }
        user.setStatus(1);
        user.setRegisterIp(SecurityUtils.getSubject().getSession().getHost());
        user.setCreateTime(new Date());
        if (StringUtils.isNotBlank(name)) {
            user.setNickName(name);
            sb.append("\n").append("nickName-").append(name);
        }
        logger.debug(sb.toString());
        int up = userService.insertSelective(user);
        if (up != 1) {
            ret.setCoder(WebResult.Coder.C2001);
            logger.error("用户[{}]新增员工用户信息-{}", sessionUser.getUserId(), ret.getMsg());
            return ret;
        }

        Employee employee = new Employee();
        employee.setUserId(userId);
        sb = new StringBuilder("Employee : userId-").append(userId);
        if (StringUtils.isNotBlank(name)) {
            employee.setName(name);
            sb.append("\n").append("name-").append(name);
        }
        if (StringUtils.isNotBlank(idcard)) {
            employee.setIdcard(idcard);
            sb.append("\n").append("idcard-").append(idcard);
        }
        if (null != sex) {
            employee.setSex(sex.name());
            sb.append("\n").append("sex-").append(sex.name());
        }
        if (StringUtils.isNotBlank(address)) {
            employee.setAddress(address);
            sb.append("\n").append("address-").append(address);
        }
        if (StringUtils.isNotBlank(nativePlace)) {
            employee.setNativePlace(nativePlace);
            sb.append("\n").append("nativePlace-").append(nativePlace);
        }
        try {
            Date birthday = df.parse(birth);
            employee.setBirth(birthday);
            sb.append("\n").append("birth-").append(birth);
        } catch (Exception ex) {
            logger.error("参数错误，birth：" + birth + "不是可解析的日期格式");
        }
        if (null != education) {
            employee.setEducation(education.name());
            sb.append("\n").append("education-").append(education.name());
        }
        try {
            Date entry = df.parse(entryTime);
            employee.setEntryTime(entry);
            sb.append("\n").append("entryTime-").append(entryTime);
        } catch (Exception ex) {
            logger.error("参数错误，entryTime：" + entryTime + "不是可解析的日期格式");
        }
        if (null != maritalstatus) {
            employee.setMaritalstatus(maritalstatus.name());
            sb.append("\n").append("maritalstatus-").append(maritalstatus.name());
        }
        if (null != post) {
            employee.setPost(post.name());
            sb.append("\n").append("post-").append(post.name());
        }
        if (StringUtils.isNotBlank(storeId)) {
            employee.setStoreId(storeId);
            sb.append("\n").append("storeId-").append(storeId);
        }
        employee.setStatus(EmployeeStatus.在职.name());
        logger.debug(sb.toString());
        up = employeeService.insertSelective(employee);
        if (up != 1) {
            ret.setCoder(WebResult.Coder.C2001);
            logger.error("用户[{}]新增员工基本信息-{}", sessionUser.getUserId(), ret.getMsg());
            userService.deleteByPrimaryKey(user.getUserId());
            return ret;
        }
        if (StringUtils.isNotBlank(roleId)) {
            SUserRoleKey userRoleKey = new SUserRoleKey();
            userRoleKey.setRoleId(roleId);
            userRoleKey.setUserId(userId);
            up = userRoleService.insertSelective(userRoleKey);
            if (up != 1) {
                ret.setCoder(WebResult.Coder.C2001);
                logger.error("用户[{}]新增员工权限信息-{}", sessionUser.getUserId(), ret.getMsg());
                userService.deleteByPrimaryKey(user.getUserId());
                employeeService.deleteByPrimaryKey(userId);
                return ret;
            }
        }
        userLogService.info(sessionUser.getUserId(), SecurityUtils.getSubject().getSession().getHost(), "新增员工信息:{0}", userId);
        return ret.setCoder(WebResult.Coder.SUCCESS);
    }

    /**
     * 员工信息查看"
     *
     * @param userId
     * @return
     */
    @RequiresPermissions("employee:add")
    @ApiOperation(value = "员工信息查看")
    @RequestMapping(value = "/view", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public WebResult<EmployeeVo> view(@ApiParam(value = "员工ID") @RequestParam(required = true) String userId) {
        WebResult<EmployeeVo> ret = new WebResult<>();
        SUser sessionUser = (SUser) SecurityUtils.getSubject().getPrincipal();
        logger.info("用户[{}]查看员工信息：{}", sessionUser.getUserId(), userId);
        EmployeeExample example = new EmployeeExample();
        example.createCriteria().andUserIdEqualTo(userId);
        ret.setAttach(employeeVoService.selectByPrimaryKey(userId));
        userLogService.info(sessionUser.getUserId(), SecurityUtils.getSubject().getSession().getHost(), "查看员工信息:{0}", userId);
        return ret.setCoder(WebResult.Coder.SUCCESS);
    }

    @ResponseBody
    @RequestMapping("/edit")
    @ApiOperation(value = "修改员工信息")
    @RequiresPermissions("employee:edit")
    public WebResult<String> edit(
            @ApiParam(value = "用户ID") @RequestParam(required = true) String userId,
            @ApiParam(value = "登录帐号") @RequestParam(required = true) String account,
            @ApiParam(value = "登录密码") @RequestParam(required = true) String password,
            @ApiParam(value = "员工姓名") String name,
            @ApiParam(value = "身份证号") String idcard,
            @ApiParam(value = "员工性别") Sex sex,
            @ApiParam(value = "联系电话") @RequestParam(required = true) String tel,
            @ApiParam(value = "联系地址") String address,
            @ApiParam(value = "籍贯") String nativePlace,
            @ApiParam(value = "出生日期") String birth,
            @ApiParam(value = "邮箱地址") @RequestParam(required = true) String email,
            @ApiParam(value = "学历") Education education,
            @ApiParam(value = "入职时间") String entryTime,
            @ApiParam(value = "婚姻状态") MaritalStatus maritalstatus,
            @ApiParam(value = "当前职位") Post post,
            @ApiParam(value = "门店ID") String storeId,
            @ApiParam(value = "角色ID") String roleId,
            @ApiParam(value = "员工状态") EmployeeStatus employeeStatus) {
        WebResult<String> ret = new WebResult<>();
        SUser sessionUser = (SUser) SecurityUtils.getSubject().getPrincipal();
        logger.info("用户[{}]修改员工信息：{}", sessionUser.getUserId(), userId);
        SUserExample mUserEp;
        List<SUser> sUsers;
        if (StringUtils.isNotBlank(account)) {
            mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserAccountEqualTo(account);
            sUsers = userService.selectByExample(mUserEp);
            if (sUsers != null && !sUsers.isEmpty() && !sUsers.get(0).getUserId().equals(userId)) {
                return new WebResult<String>().setCoder(WebResult.Coder.C1211);
            }
        }
        if (StringUtils.isNotBlank(email)) {
            mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserMailEqualTo(email);
            sUsers = userService.selectByExample(mUserEp);
            if (sUsers != null && !sUsers.isEmpty() && !sUsers.get(0).getUserId().equals(userId)) {
                return new WebResult<String>().setCoder(WebResult.Coder.C1212);
            }
        }
        if (StringUtils.isNotBlank(tel)) {
            mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserTelEqualTo(tel);
            sUsers = userService.selectByExample(mUserEp);
            if (sUsers != null && !sUsers.isEmpty() && !sUsers.get(0).getUserId().equals(userId)) {
                return new WebResult<String>().setCoder(WebResult.Coder.C1213);
            }
        }
        StringBuilder sb = new StringBuilder();
        SUser user = new SUser();
        user.setUserId(userId);
        sb.append("userId-").append(userId);
        sb.append("\n").append("account-").append(account);
        user.setUserAccount(account);
        if (StringUtils.isNotBlank(password) && !"******".equals(password = password.trim())) {
            String pwd = PwdUtil.getPwd(password);
            sb.append("\n").append("password-").append(password);
            user.setUserPwd(pwd);
        }
        sb.append("\n").append("tel-").append(tel);
        user.setUserTel(tel);
        sb.append("\n").append("email-").append(email);
        user.setUserMail(email);
        logger.debug(sb.toString());
        int up = userService.updateByPrimaryKeySelective(user);
        if (up != 1) {
            ret.setCoder(WebResult.Coder.C2001);
            logger.error("用户[{}]修改员工登陆信息-{}", sessionUser.getUserId(), ret.getMsg());
            return ret;
        }

        sb = new StringBuilder();
        Employee employee = new Employee();
        employee.setUserId(userId);
        sb.append("userId-").append(userId);
        employee.setName(name);
        sb.append("\n").append("name-").append(name);
        employee.setIdcard(idcard);
        sb.append("\n").append("idcard-").append(idcard);
        employee.setSex(sex.name());
        sb.append("\n").append("sex-").append(sex.name());
        employee.setAddress(address);
        sb.append("\n").append("address-").append(address);
        employee.setNativePlace(nativePlace);
        sb.append("\n").append("nativePlace-").append(nativePlace);
        try {
            Date birthday = df.parse(birth);
            employee.setBirth(birthday);
            sb.append("\n").append("birth-").append(birth);
        } catch (Exception ex) {
            logger.error("参数错误，birth：" + birth + "不是可解析的日期格式");
        }
        employee.setEducation(education.name());
        sb.append("\n").append("education-").append(education.name());
        try {
            Date entry = df.parse(entryTime);
            employee.setEntryTime(entry);
            sb.append("\n").append("entryTime-").append(entryTime);
        } catch (Exception ex) {
            logger.error("参数错误，entryTime：" + entryTime + "不是可解析的日期格式");
        }
        employee.setMaritalstatus(maritalstatus.name());
        sb.append("\n").append("maritalstatus-").append(maritalstatus.name());
        employee.setPost(post.name());
        sb.append("\n").append("post-").append(post.name());
        employee.setStoreId(storeId);
        sb.append("\n").append("storeId-").append(storeId);
        employee.setStatus(employeeStatus.name());
        sb.append("\n").append("employeeStatus-").append(employeeStatus.name());
        logger.debug(sb.toString());
        up = employeeService.updateByPrimaryKeySelective(employee);
        if (up != 1) {
            ret.setCoder(WebResult.Coder.C2001);
            logger.error("用户[{}]修改员工基本信息-{}", sessionUser.getUserId(), ret.getMsg());
            return ret;
        }

        if (StringUtils.isNotBlank(roleId)) {
            SUserRoleExample urExample = new SUserRoleExample();
            urExample.createCriteria().andUserIdEqualTo(userId);
            userRoleService.deleteByExample(urExample);
            SUserRoleKey userRoleKey = new SUserRoleKey();
            userRoleKey.setRoleId(roleId);
            userRoleKey.setUserId(userId);
            userRoleService.insert(userRoleKey);
        }
        userLogService.info(sessionUser.getUserId(), SecurityUtils.getSubject().getSession().getHost(), "修改员工信息:{0}", userId);
        return new WebResult<String>().setCoder(WebResult.Coder.SUCCESS);
    }

    @ResponseBody
    @RequestMapping("/delete")
    @ApiOperation(value = "删除员工信息")
    @RequiresPermissions("employee:delete")
    public WebResult<String> delete(@ApiParam(value = "用户ID") @RequestParam(required = true) String userId) {
        WebResult<String> ret = new WebResult<>();
        SUser sessionUser = (SUser) SecurityUtils.getSubject().getPrincipal();
        logger.info("用户[{}]删除员工信息：{}", sessionUser.getUserId(), userId);
        Employee employee = new Employee();
        employee.setUserId(userId);
        employee.setDelFlag(1);
        int up = employeeService.updateByPrimaryKeySelective(employee);
        if (1 != up) {
            ret.setCoder(WebResult.Coder.C2001);
            logger.error("用户[{}]删除员工基本信息失败-{}", sessionUser.getUserId(), ret.getMsg());
        }
        SUser user = new SUser();
        user.setUserId(userId);
        user.setStatus(0);
        up = userService.updateByPrimaryKeySelective(user);
        if (1 != up) {
            ret.setCoder(WebResult.Coder.C2001);
            logger.error("用户[{}删除员工登陆信息失败-{}", sessionUser.getUserId(), ret.getMsg());
        }
        userLogService.info(sessionUser.getUserId(), SecurityUtils.getSubject().getSession().getHost(), "删除员工信息:{0}", userId);
        return new WebResult<String>().setCoder(WebResult.Coder.SUCCESS);
    }

    @ResponseBody
    @ApiOperation(value = "用户帐号验证")
    @RequestMapping(value = "/validate/account", method = {RequestMethod.GET, RequestMethod.POST})
    public Object validateAccount(@ApiParam(value = "用户ID") String userId,
            @ApiParam(value = "用户帐号") @RequestParam(required = true) String account) {
        if (StringUtils.isNotBlank(account)) {
            SUserExample mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserAccountEqualTo(account);
            List<SUser> sUsers = userService.selectByExample(mUserEp);
            if (sUsers == null || sUsers.isEmpty() || sUsers.get(0).getUserId().equals(userId)) {
                return true;
            }
        }
        return false;
    }

    @ResponseBody
    @ApiOperation(value = "用户邮箱验证")
    @RequestMapping(value = "/validate/email", method = {RequestMethod.GET, RequestMethod.POST})
    public Object validateEmail(@ApiParam(value = "用户ID") String userId,
            @ApiParam(value = "用户邮箱") @RequestParam(required = true) String email) {
        if (StringUtils.isNotBlank(email)) {
            SUserExample mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserMailEqualTo(email);
            List<SUser> sUsers = userService.selectByExample(mUserEp);
            if (sUsers == null || sUsers.isEmpty() || sUsers.get(0).getUserId().equals(userId)) {
                return true;
            }
        }
        return false;
    }

    @ResponseBody
    @ApiOperation(value = "用户手机验证")
    @RequestMapping(value = "/validate/tel", method = {RequestMethod.GET, RequestMethod.POST})
    public Object validateTel(@ApiParam(value = "用户ID") String userId,
            @ApiParam(value = "用户手机") @RequestParam(required = true) String tel) {
        if (StringUtils.isNotBlank(tel)) {
            SUserExample mUserEp = new SUserExample();
            mUserEp.createCriteria().andUserTelEqualTo(tel);
            List<SUser> sUsers = userService.selectByExample(mUserEp);
            if (sUsers == null || sUsers.isEmpty() || sUsers.get(0).getUserId().equals(userId)) {
                return true;
            }
        }
        return false;
    }
}
